﻿using System;
using System.Linq;
using DZLib.ExtendFramework.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DZLib.ExtendFramework.UnitTests.Generic.ExtendIEnumerableTest
{
    [TestClass]
    public class ResizeTest
    {
        [TestMethod]
        public void ResizeExpandTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 0, 0, 0 };
            var actual = testCase.Resize(10);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeClipTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expected = new int[] { 1, 2, 3, 4, 5 };
            var actual = testCase.Resize(5);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeLowerBoundTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            try
            {
                var actual = testCase.Resize(-1);
            }
            catch (ArgumentOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }

        [TestMethod]
        public void ResizeEmptyTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expected = new int[] { };
            var actual = testCase.Resize(0);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeFromEmptyTest()
        {
            var testCase = new int[] { };
            var expected = new int[] { 0, 0, 0, 0, 0, 0, 0 };
            var actual = testCase.Resize(7);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeFromEmptyToEmptyTest()
        {
            var testCase = new int[] { };
            var expected = new int[] { };
            var actual = testCase.Resize(0);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeInitExpandTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 255, 255, 255 };
            var actual = testCase.Resize(10, 255);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeInitClipTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expected = new int[] { 1, 2, 3, 4, 5 };
            var actual = testCase.Resize(5, 255);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeInitLowerBoundTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            try
            {
                var actual = testCase.Resize(-1, 255);
            }
            catch (ArgumentOutOfRangeException)
            {
                Assert.IsTrue(true);
            }
        }

        [TestMethod]
        public void ResizeInitEmptyTest()
        {
            var testCase = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            var expected = new int[] { };
            var actual = testCase.Resize(0, 255);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeInitFromEmptyTest()
        {
            var testCase = new int[] { };
            var expected = new int[] { 255, 255, 255, 255, 255, 255, 255 };
            var actual = testCase.Resize(7, 255);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void ResizeInitFromEmptyToEmptyTest()
        {
            var testCase = new int[] { };
            var expected = new int[] { };
            var actual = testCase.Resize(0, 255);
            Assert.IsTrue(expected.SequenceEqual(actual));
        }
    }
}
